package com.cjm.task2.impl;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;

import java.util.Objects;


@SuppressWarnings("unused")
public class UserCommandLineRunner implements CommandLineRunner {

    Environment environment;

    //使用构造方法方式，注入Environment
    public UserCommandLineRunner(Environment environment){
        this.environment=environment;
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("利用Spring Boot自动装配的CommandLineRunner");
        //利用random的RandomValuePropertySource产生一个32位随机字符串
        System.out.println("生成一个随机字符串:".concat(Objects.requireNonNull(environment.getProperty("random."))));
    }
}
